package com.jckl.foodathon.locationService;

import org.restlet.ext.jackson.JacksonRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;

import android.os.StrictMode;
import android.util.Log;

import com.jckl.foodathon.model.Coordinate;

public class LocalityQuery {
	
	public String getLocality(double latitude, double longitude){
		
		String returnValue = "";
		try {
			
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
			StrictMode.setThreadPolicy(policy); 
			
			Coordinate coordinate = new Coordinate(latitude, longitude);
			
			ClientResource cr = new ClientResource("http://foodathon42.appspot.com/geoCoding");
			JacksonRepresentation<Coordinate> coord = new JacksonRepresentation<Coordinate>(coordinate);
			Representation rep = cr.put(coord);

			returnValue = rep.getText();
			
			
		} catch (Exception ex){
			ex.printStackTrace();
			Log.v("Restlet", ex.getLocalizedMessage());
		}
		
		return returnValue;
	}

}
